//
//  BackupsSwitchView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/27.
//

import SwiftUI

//温馨提示弹窗
struct CommonTip2DialogView: View {
    let title: String
    let text :AttributedString
    let alignment: TextAlignment
    let dismiss: () -> Void
    @State private var textHeight: CGFloat = 0
    @State private var availableHeight: CGFloat = 600 //暂时写死，虽然GeometryReader可以获取ScrollView高度，但是设置min就失效了，咱死无解
    
    var body: some View {
        PopupCenterView(title: title, dismiss: dismiss) {
            ZStack {
                ScrollView {
                    Text(text)
                        .font(.system(size: 15))
                        .foregroundStyle(.bgNormalText2)
                        .multilineTextAlignment(alignment) // 设置文本对齐方式
                        .lineSpacing(4)//行间距
                        .tracking(2.5)//字符
                        .fixedSize(horizontal: false, vertical: true) // 允许垂直方向自适应大小
                        .frame(minHeight: 50)
                        .background(
                            GeometryReader { textGeometry in
                                Color.clear
                                    .onAppear {
                                        textHeight = textGeometry.size.height
                                    }
                            }
                        )
                }.frame(height: min(textHeight, availableHeight))
            }.padding(.horizontal,10)
        }
    }
}

//#Preview {
//    CommonTipDialogView()
//}
//定义预览提供者
struct CommonTip2DialogView_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: CommonTip2DialogView(title:"温馨提示",text: "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试", alignment: .center){})
    }
}
